package com.zy.Conterller;

import com.zy.vo.ResultVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLException;


@RestControllerAdvice
@Slf4j
public class GlobalExcptionCatch {
    /**
     * 全局异常扑捉
     * @param ex
     * @return
     */
    @ExceptionHandler(RuntimeException.class)
    public ResultVo errorHandler(RuntimeException ex){
        if (ex instanceof UnauthorizedException){
            log.error("用户无此权限",ex);
        }else{
            log.error(ex.getMessage(),ex);
        }

        return ResultVo.fail("查询操作失败",ex);
    }
}
